package com.eos.control.action.customer;

import com.eos.business.service.SysCustomerBusinessService;
import com.eos.common.tool.DataCacheUtil;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysCustomer;
import com.eos.orm.mybatis.model.SysUser;
import com.hf.utils.StringUtil;

public class UpdateCustomerAction extends AbstractBaseAction {
	private static final long serialVersionUID = 9027829215995775359L;
	private Integer customerId;
	private String customerName;
	private String nickName;
	private String legalPerson;
	private String linkAddr;
	private String postCode;
	private String customerType;
	private String sysUser;
	private String customerDesc;
	private String customerCode;

	public void setCustomerId(Integer customerId) {
		this.customerId = customerId;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public void setLegalPerson(String legalPerson) {
		this.legalPerson = legalPerson;
	}

	public void setLinkAddr(String linkAddr) {
		this.linkAddr = linkAddr;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public void setCustomerType(String customerType) {
		this.customerType = customerType;
	}

	public void setSysUser(String sysUser) {
		this.sysUser = sysUser;
	}

	public void setCustomerDesc(String customerDesc) {
		this.customerDesc = customerDesc;
	}

	public void setCustomerCode(String customerCode) {
		this.customerCode = customerCode;
	}

	@Override
	public String execute() {
		try {
			if (null == customerId || customerId.longValue() <= 0) {
				statusCode = "300";
				message = "参数错误,保存供应商信息失败!";
			} else {
				SysUser loginUser = (SysUser) getSession().getAttribute("SysUser");
				String loginUserId = loginUser.getId() + "";
				SysCustomer customer = new SysCustomer();
				customer.setId(customerId);
				customer.setCustomerAddress(linkAddr);
				customer.setCustomerDesc(customerDesc);
				customer.setCustomerName(customerName);
				customer.setCustomerPostcode(postCode);
				customer.setCustomerShort(nickName);
				customer.setCustomerType(customerType);
				String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
				customer.setLegalPerson(legalPerson);
				customer.setModifyTime(strTime);
				if(StringUtil.isEmpty(sysUser) || "0".equals(sysUser))
					sysUser = loginUserId;
				customer.setSysUserId(sysUser);
				customer.setCustomerCode(customerCode);
				customer.setUpdateUserId(loginUserId);
				SysCustomerBusinessService scbs = new SysCustomerBusinessService();
				String exeStatus = scbs.updateCustomerSelective(customer);
				if("SUCCESS".equals(exeStatus)){
					statusCode = "200";
					message = "修改客户信息成功!";
					DataCacheUtil.clearSysCustomerMap();
				}else{
					statusCode = "300";
					message = "系统繁忙, 修改客户信息失败!";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常,保存供应商信息失败!";
		}
		return SUCCESS;
	}
}
